package com.hong.day03.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.runtime.ProcessInstance;

/**
 * @Auther: csh
 * @Date: 2019/11/21 18:38
 * @Description:全部流程实例挂起与激活
 */
public class SuspendProcessInstance {
    public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到RepositoryService
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
        //3.查询流程定义的对象
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionKey("holiday")
                .singleResult();
        //4.得到当前流程定义的实例是否都为暂停状态
        boolean suspended = processDefinition.isSuspended();
        System.out.println(suspended);
        //5.判断
        if(suspended){
            //说明是暂停 就可以激活操作
            repositoryService.activateProcessDefinitionById(processDefinition.getId(),true,null);
            System.out.println("实例:"+processDefinition.getId()+"激活");
        }else{
            repositoryService.suspendProcessDefinitionById(processDefinition.getId(),false,null);
            System.out.println("实例:"+processDefinition.getId()+"挂起");
        }
    }
}
